<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="tutorial.css">
<TITLE>
Syntax
</TITLE>
</HEAD>
<BODY >
<A HREF="tutorial092.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="tutorial091.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial094.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc180">13.2</A>&nbsp;&nbsp;Syntax</H2><UL>
<LI><A HREF="tutorial093.html#toc89">Setting and Getting Tentative Values</A>
<LI><A HREF="tutorial093.html#toc90">Building and Accessing Conflict Sets</A>
<LI><A HREF="tutorial093.html#toc91">Propagating Conflicts</A>
</UL>

<A NAME="@default339"></A>
<A NAME="toc89"></A>
<H3 CLASS="subsection"><A NAME="htoc181">13.2.1</A>&nbsp;&nbsp;Setting and Getting Tentative Values</H3>
With the <TT>repair</TT> library each variable can be given a <EM>tentative</EM> value. This is different from instantiating the variable.
Rather the tentative value is a piece of updatable information
associated with the variable.
The tentative value can be changed repeatedly during search, not just
on backtracking. 
The value is set using the syntax <CODE>tent_set</CODE>, and retrieved using
<CODE>tent_get</CODE>. 
For example the following query writes first 1 and then 2:
<BLOCKQUOTE CLASS="quote">
<PRE CLASS="verbatim">
?- X tent_set 1, 
   X tent_get Tent1, 
   writeln(Tent1), 
   X tent_set 2,
   X tent_get Tent2,
   writeln(Tent2).
</PRE></BLOCKQUOTE>
Throughout this query <I>X</I> remains a variable.<BR>
<BR>
A tentative variable may violate constraints.
The following query writes <CODE>succeed</CODE>, because
setting the tentative value to 1 does not cause a failure:
<BLOCKQUOTE CLASS="quote">
<PRE CLASS="verbatim">
?- X $&gt; 2,
   X tent_set 1,
   writeln(succeed).
</PRE></BLOCKQUOTE>
<A NAME="toc90"></A>
<H3 CLASS="subsection"><A NAME="htoc182">13.2.2</A>&nbsp;&nbsp;Building and Accessing Conflict Sets</H3>
<A NAME="@default340"></A>
The relation between constraints and tentative values can be
maintained in two ways.
The first method is by <EM>monitoring</EM> a constraint for conflicts. 
<BLOCKQUOTE CLASS="quote">
<PRE CLASS="verbatim">
?- X $&gt; 2 r_conflict myset,
   X tent_set 1,
   writeln(succeed).
</PRE></BLOCKQUOTE>
This query also succeeds - but additionally it creates a <EM>conflict
set</EM> named 
<CODE>myset</CODE>. Because <I>X</I> $&gt; 2 is violated by the tentative value of
<I>X</I>, the constraint is recorded in the conflict set. The conflict set
written out by the following query is <CODE>[X{1} $&gt; 2]</CODE>:
<BLOCKQUOTE CLASS="quote">
<PRE CLASS="verbatim">
?- X $&gt; 2 r_conflict myset,
   X tent_set 1,
   conflict_constraints(myset,Conflicts),
   writeln(Conflicts).
</PRE></BLOCKQUOTE>
The conflict can be <EM>repaired</EM> by changing the tentative value of
the variable which causes it:

	<TABLE CELLPADDING=10>
<TR><TD BGCOLOR="#CCCCFF">
	<BLOCKQUOTE CLASS="quote"><PRE>
?- X $&gt; 2 r_conflict myset,
   X tent_set 1,
   conflict_constraints(myset,Conflicts),
   X tent_set 3,
   conflict_constraints(myset,NoConflicts).
</PRE></BLOCKQUOTE></TD>
</TR></TABLE>
This program instantiates <CODE>Conflicts</CODE> to <CODE>[X{1} $&gt; 2]</CODE>,
but <CODE>NoConflicts</CODE> is instantiated to <CODE>[]</CODE>.<BR>
<BR>
<A NAME="toc91"></A>
<H3 CLASS="subsection"><A NAME="htoc183">13.2.3</A>&nbsp;&nbsp;Propagating Conflicts</H3>
Arithmetic equality (<CODE>=:=</CODE>, <CODE>$=</CODE>) constraints, instead of
monitoring for conflicts, 
can be maintained by propagating tentative values. 
To do so, they must be rewritten in a functional syntax.
Consider the constraint <CODE>X =:= Y+1</CODE>.
For propagation of tentative values, this must
be rewritten in the form <CODE>X tent_is Y+1</CODE>.
If the tentative value of <I>Y</I> is set to 1, then this will be
propagated to the tentative value
of <I>X</I>. The following query writes out the value 2.
<BLOCKQUOTE CLASS="quote">
<PRE CLASS="verbatim">
?- X tent_is Y+1,
   Y tent_set 1,
   X tent_get(TentX),
   writeln(TentX).
</PRE></BLOCKQUOTE>
Each time the tentative value of <I>Y</I> is changed, the value of <I>X</I> is
kept in step, so the following writes out the value 3:
<BLOCKQUOTE CLASS="quote">
<PRE CLASS="verbatim">
?- X tent_is Y+1,
   Y tent_set 1,
   Y tent_set 2,
   X tent_get(TentX),
   writeln(TentX).
</PRE></BLOCKQUOTE>
<A NAME="@default341"></A>
<A NAME="@default342"></A>
<A NAME="@default343"></A>
<A NAME="@default344"></A>
<A NAME="@default345"></A>

	<BLOCKQUOTE CLASS="figure"><DIV CLASS="center"><HR WIDTH="80%" SIZE=2></DIV>
	<DIV CLASS="center">
	<TABLE CELLPADDING=10>
<TR><TD BGCOLOR="#DB9370">
	Repair supports the 
following primitives:
<UL CLASS="itemize"><LI CLASS="li-itemize">
<TT>tent_set/2</TT>
<LI CLASS="li-itemize"><TT>tent_get/2</TT>
<LI CLASS="li-itemize"><TT>r_conflict/2</TT>
<LI CLASS="li-itemize"><TT>conflict_constraints/2</TT>
<LI CLASS="li-itemize"><TT>tent_is/2</TT>
</UL>
(and some others that are not covered in this tutorial).

	</TD>
</TR></TABLE>
	</DIV>
	<BR>
<BR>
<DIV CLASS="center">Figure 13.2: Syntax</DIV><BR>
<BR>

	<DIV CLASS="center"><HR WIDTH="80%" SIZE=2></DIV></BLOCKQUOTE>
<HR>
<A HREF="tutorial092.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="tutorial091.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="tutorial094.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
